class ResultCode {
	static Success = 1000;
	// 服务异常
	static ServerError = 10002;
}

class Result {
	/**
	 * 成功
	 * @param {*} code
	 * @param {*} data
	 * @returns
	 */
	static Success(data = null, code = ResultCode.Success) {
		return {
			code: code,
			data: data
		};
    }
    
    /**
     * 分页
     * @param {*} pageIndex 
     * @param {*} total 
     * @param {*} data 
     * @returns 
     */
    static Paging(pageIndex, total, data) {
        return {
			code: ResultCode.Success,
            data: {
                page: Number(pageIndex),
                total: Number(total),
                list: data || null
            }
		};
    }

	/**
	 * 失败
	 * @param {*} code
	 * @param {*} message
	 * @param {*} data
	 * @returns
	 */
	static Failed(message, code = ResultCode.ServerError, data = null) {
		return {
			code: code,
			data: data,
			message: message
		};
	}
}

module.exports = {
	Result,
	ResultCode
};
